package com.kevin.j2eeToolBox.innerClass;

import java.util.Date;

public class InnerClass {

	public static String staticStr = "Static String";
	public String str = "Hello World";
	public final String finalStr = "final String";

	public void foo() {
		System.out.println("not static method");
	}

	public static void foo1() {
		System.out.println("static method");
	}

	// 静态内部类，只能访问外部类中的静态变量
	public static class StaticInnerClass {

		private String staticStr = "private String";

		public void Say() {
			System.out.println(InnerClass.staticStr);
			// System.out.println(str);
			// InnerClass.this.foo();
			foo1();
		}
	}

	public void getTime(Date date) {
		System.out.println(date.toString());
	}

	public class MemberInnerClass {
		public void Say() {
			System.out.println(InnerClass.staticStr);
			System.out.println(str);
			InnerClass.this.foo();
			foo1();
		}
	}

	public void doSomething() {
		final String str1 = "final String";
		String a = "test";

		class LocalInnerClass {
			public void foo() {
				System.out.println(finalStr);
				System.out.println(str1);
				System.out.println(str);
				// System.out.println(a);
			}
		}

		new LocalInnerClass().foo();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		InnerClass.StaticInnerClass staticInnerClass = new InnerClass.StaticInnerClass();
		staticInnerClass.Say();

		InnerClass.MemberInnerClass properyInnerClass = new InnerClass().new MemberInnerClass();
		properyInnerClass.Say();

		InnerClass inner = new InnerClass();

		inner.doSomething();
		inner.getTime(new Date() {

			@Override
			public String toString() {
				// TODO Auto-generated method stub
				return "now is " + super.toString();
			}
		});
	}
}
